package org.sample.thread;

import org.sample.commons.StopWatch;

import java.util.concurrent.*;

public class ThreadPool {
    public static int i = 1;

    public static void main(String[] args) throws Exception {
//        ExecutorService pool = Executors.newCachedThreadPool();
        ExecutorService pool = Executors.newFixedThreadPool(4);

        StopWatch stopWatch = new StopWatch();
        Future<Integer> a = pool.submit(() -> {
            Thread.sleep(2000);
            return 1;
        });

        Future<Integer> b = pool.submit(() -> {
            Thread.sleep(4000);
            return 2;
        });

        Future<Integer> c = pool.submit(() -> {
            Thread.sleep(2000);
            return 3;
        });

        int i = a.get() + b.get() + c.get();
        System.out.println(i);
        stopWatch.print();
        pool.shutdownNow();

//        Future<?> submit = pool.submit(new FutureTask<String>(new Callable<String>() {
//            @Override
//            public String call() throws Exception {
//                return null;
//            }
//        }));

    }
}